package DynamicProgramming;

import java.util.Arrays;

public class _650_2KeysKeyboard {
    public int minSteps(int n) {
        int[] dp = new int[n+1];
        Arrays.fill(dp, 9999);
        dp[0] = dp[1] = 0;
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    int divided = i / j;
                    dp[i] = Math.min(dp[divided] + j, dp[i]);
                    dp[i] = Math.min(dp[j] + divided, dp[i]);
                }
            }
        }
        return dp[n];
    }
}
